<template>
  <div class="info_config_page">
    <div class="common_form_search">
      <el-form ref="searchForm" :inline="true" :model="searchForm" class="form-inline">
        <el-form-item label="订单号">
          <el-input v-model="searchForm.orderNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="租期编号">
          <el-input v-model="searchForm.number" placeholder="请输入租期编号" />
        </el-form-item>
        <el-form-item label="凭证编号">
          <el-input v-model="searchForm.alipayNo" placeholder="请输入凭证编号" />
        </el-form-item>
        <el-form-item label="归还方式">
          <el-select v-model="searchForm.returnType" clearable placeholder="请选择">
            <el-option :value="1" label="预授权代扣" />
            <el-option :value="2" label="支付宝代扣" />
            <el-option :value="3" label="主动还款" />
            <el-option :value="4" label="其他" />
          </el-select>
        </el-form-item>
        <el-form-item label="归还状态">
          <el-select v-model="searchForm.returnStatus" clearable placeholder="请选择">
            <el-option :value="1" label="足额归还" />
            <el-option :value="2" label="部分归还" />
            <el-option :value="3" label="未归还" />
            <el-option :value="4" label="退租" />
            <el-option :value="5" label="订单已完结" />
          </el-select>
        </el-form-item>
        <el-form-item label="归还时间">
          <my-date-picker ref="myDatePicker" />
        </el-form-item>
        <!-- <el-form-item label="供应商">
          <el-input
            v-model="searchForm.cert_no"
            placeholder="请输入供应商"
          ></el-input>
        </el-form-item> -->
        <el-form-item label="上链状态">
          <el-select v-model="searchForm.status" clearable placeholder="请选择">
            <el-option :value="0" label="未上链" />
            <el-option :value="1" label="已上链" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button size="small" @click="search()" type="primary">查询</el-button>
          <el-button size="small" @click="reset()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-divider />
    <div class="flex align-center table-top-btns">
      <h5 class="flex align-center">
        <svg-icon style="margin-right: 15px" icon-class="list" :size="15" />数据列表
      </h5>
    </div>
    <el-table :data="tableData" border>
      <el-table-column align="center" header-align="center" fixed prop="id" label="ID" width="80" />
      <el-table-column align="center" header-align="center" fixed prop="order_no" label="订单ID" width="120" />
      <el-table-column align="center" header-align="center" label="租期编号" width="110">
        <template slot-scope="scope">
          <span>第{{ scope.row.which_period }}期</span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="归还状态">
        <template slot-scope="scope">
          <span>
            {{ scope.row.rent_status == 1 ? '足额归还' : scope.row.rent_status == 2 ? '部分归还' : scope.row.rent_status == 3 ? '未归还' : scope.row.rent_status == 4 ? '退租' : '订单已完结 ' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="租⾦归还金额">
        <template slot-scope="scope">
          <span>￥{{ scope.row.rent }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="归还方式">
        <template slot-scope="scope">
          <span>
            {{ scope.row.pay_type == 1 ? '预授权代扣' : scope.row.pay_type == 2 ? '支付宝代扣' : scope.row.pay_type == 3 ? '主动还款' : '其他 ' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" prop="begin_time" label="归还时间" width="100" />
      <el-table-column align="center" header-align="center" prop="alipay_trade_no" label="还款凭证类型" />
      <el-table-column align="center" header-align="center" prop="alipay_trade_no" label="还款凭证编号" />
      <el-table-column align="center" header-align="center" label="手续费" width="100">
        <template slot-scope="scope">
          <span>￥{{ scope.row.charge }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" header-align="center" label="剩余归还期数" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.surplusLease }}期</span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        align="center"
        header-align="center"
        prop="member_id"
        label="供应商"
      /> -->
      <el-table-column align="center" header-align="center" prop="chain_time" label="上链时间" width="100" />
      <el-table-column align="center" header-align="center" prop="chain_status" label="上链状态" width="100">
        <template slot-scope="scope">
          <el-tag class="pointer" :type="scope.row.chain_status === 0 ? 'primary' : 'success'" @click="getParams(scope.row.chain_params)" disable-transitions>
            {{ scope.row.chain_status == 0 ? "未上链" : "已上链" }}
          </el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column
        align="center"
        header-align="center"
        fixed="right"
        label="操作"
        width="100"
      >
        <template slot-scope="scope">
          <div class="operate_col">
            <el-button
              @click="onChain(scope.row.id)"
              type="primary"
              size="small"
            >
              上链
            </el-button>
          </div>
        </template>
      </el-table-column> -->
    </el-table>
    <custom-page ref="customPage" :total="total" @getList="getList" />
    <param-dialog :dialogVisible="dialogVisible" :dialogType="dialogType" :requestInfo="requestInfo" :responseInfo="responseInfo" @close="closeDialog" />
  </div>
</template>

<script>
import { getRentalList } from '@/api/lease'
import customPage from '@/components/customPage'
import myDatePicker from '@/components/myDatePicker'
import paramDialog from './child/paramDialog.vue'
export default {
  components: { customPage, myDatePicker, paramDialog },
  data() {
    return {
      tableData: [],
      total: 0,
      searchForm: {
        orderNo: '',
        number: '',
        alipayNo: '',
        returnType: '',
        returnStatus: '',
        leaseTime: '',
        status: ''
      },
      dialogVisible: false,
      dialogType: 1,
      requestInfo: {},
      responseInfo: {}
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    search() {
      const pickerVal = this.$refs.myDatePicker.getVal()
      if (pickerVal !== 'error') {
        this.searchForm.leaseTime = pickerVal
        this.$refs.customPage.page = 1
        this.getList()
      }
    },
    // 重置
    reset() {
      if (this.$refs.myDatePicker) {
        this.$refs.myDatePicker.reset()
      }
      this.searchForm = Object.assign({})
      this.getList()
    },
    getParams(row) {
      this.dialogType = 2
      this.dialogVisible = true
      let info = JSON.parse(row)
      this.requestInfo = info.request ? JSON.parse(info.request.biz_content) : {}
      this.responseInfo = info.response ? info.response : {}
    },
    closeDialog() {
      this.dialogVisible = false
    },
    onChain(id) {
      this.dialogType = 1
      this.dialogVisible = true
    },
    // 获取列表
    getList() {
      const { page, pageSize } = this.$refs.customPage
      getRentalList({
        page,
        pageSize,
        ...this.searchForm
      }).then((res) => {
        this.tableData = res.data
        this.total = res.total
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
